package service

import (
	"context"
	"youngee_b_api/db"
	"youngee_b_api/model/gorm_model"
	"youngee_b_api/model/http_model"
)

var Job *job

type job struct {
}

// CreateJob 新增岗位
func (*job) CreateJob(ctx context.Context, request http_model.AddNewJobRequest) error {
	var newJob = gorm_model.YounggeeJob{
		JobDetail:            request.JobDetail,
		JobName:              request.JobName,
		CommercialCenter:     request.CommercialCenter,
		CommercialManagement: request.CommercialManagement,
		CooperatePermission:  request.CooperatePermission,
		FinancialPermission:  request.FinancialPermission,
		SupplierId:           request.SupplierId,
	}
	err := db.CreateJob(ctx, newJob)
	if err != nil {
		return err
	}
	return nil
}

// UpdateJob 修改岗位
func (*job) UpdateJob(ctx context.Context, request http_model.UpdateJobRequest) error {
	var newJob = gorm_model.YounggeeJob{
		JobDetail:            request.JobDetail,
		JobName:              request.JobName,
		CommercialCenter:     request.CommercialCenter,
		CommercialManagement: request.CommercialManagement,
		CooperatePermission:  request.CooperatePermission,
		FinancialPermission:  request.FinancialPermission,
		SupplierId:           request.SupplierId,
	}
	err := db.UpdateJob(ctx, newJob)
	if err != nil {
		return err
	}
	return nil
}

// DeleteJob 删除岗位
func (*job) DeleteJob(ctx context.Context, request http_model.DeleteJobRequest) error {
	var newJob = gorm_model.YounggeeJob{
		JobId: request.JobId,
	}
	err := db.DeleteJob(ctx, newJob)
	if err != nil {
		return err
	}
	return nil
}
