package service

import (
	"context"
	"github.com/sirupsen/logrus"
	"youngee_b_api/db"
	"youngee_b_api/model/http_model"
)

var Task *task

type task struct {
}

func (*task) GetRecruitTime(ctx context.Context, request http_model.GetRecruitTimeRequest) (*http_model.GetRecruitTimeResponse, error) {
	recruit, err := db.GetRecruittime(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[localtask service] call GetRecruitTime error,err:%+v", err)
		return nil, err
	}
	return recruit, nil
}
func (*task) GetTalentstatusNum(ctx context.Context, request http_model.GetTalentstatusNumRequest) (*http_model.GetTalentStatusNumResponse, error) {
	statusnum, err := db.GetTalentstatusNumCount(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetTalentstatusNum error,err:%+v", err)
		return nil, err
	}
	return statusnum, nil
}

func (*task) GetList(ctx context.Context, request http_model.GetTaskListRequest) (*http_model.GetTaskListData, error) {
	secTaskList, err := db.GetProjecttaskList(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetTaskList error,err:%+v", err)
		return nil, err
	}
	return secTaskList, nil
}

func (*task) PassCoop(ctx context.Context, request http_model.PassproTaskCoopRequest) (*http_model.PassSecTaskCoopData, error) {
	_, err := db.PassProTaskCoop(ctx, request.ProjectId, request.TaskIds, request.OperatorId, request.OperateType, request.IsSpecial, request.EnterpriseId, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call PassCoop error,err:%+v", err)
		return nil, err
	}

	selectionListData := http_model.PassSecTaskCoopData{}

	return &selectionListData, nil
}

func (*task) RefuseCoop(ctx context.Context, request http_model.RefuseproTaskCoopRequest) (*http_model.RefuseproTaskCoopData, error) {

	_, err := db.RefuseproTaskCoop(ctx, request.TaskIds, request.OperatorId, request.OperateType, request.EnterpriseId)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call RefuseCoop error,err:%+v", err)
		return nil, err
	}

	projectListData := http_model.RefuseproTaskCoopData{}

	return &projectListData, nil
}

func (*task) GetTalentstatusCount(ctx context.Context, request http_model.GetTalentstatusCountRequest) (*http_model.GetTalentstatusCountResponse, error) {
	statusnum, err := db.GetTalentstatusCountNum(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetTalentstatusNum error,err:%+v", err)
		return nil, err
	}
	return statusnum, nil
}

func (*task) GetPreSketchList(ctx context.Context, request http_model.PreSketchListRequest) (*http_model.GetSketchTaskListData, error) {
	secTaskList, err := db.GetPreSketchList(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetPreSketchList error,err:%+v", err)
		return nil, err
	}
	return secTaskList, nil
}

func (*task) GetTasksketchlist(ctx context.Context, request http_model.TasksketchlistRequest) (*http_model.GetsketchtaskListData, error) {
	secTaskList, err := db.GetSketchList(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetTasksketchlist error,err:%+v", err)
		return nil, err
	}
	return secTaskList, nil
}

func (*task) GetPreLinkList(ctx context.Context, request http_model.PreLinkListRequest) (*http_model.GetprelinkListData, error) {
	secTaskList, err := db.GetPreLinkList(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call PreLinkListRequest error,err:%+v", err)
		return nil, err
	}
	return secTaskList, nil
}

func (*task) GetTaskLinklist(ctx context.Context, request http_model.TaskLinklistRequest) (*http_model.GettasklinkListData, error) {
	secTaskList, err := db.GetLinkList(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetTasksketchlist error,err:%+v", err)
		return nil, err
	}
	return secTaskList, nil
}

func (*task) GetPreDataList(ctx context.Context, request http_model.PreDataListRequest) (*http_model.GetPreDataListData, error) {
	secTaskList, err := db.GetPreDataList(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call PreLinkListRequest error,err:%+v", err)
		return nil, err
	}
	return secTaskList, nil
}

func (*task) GetTaskDatalist(ctx context.Context, request http_model.TaskDatalistRequest) (*http_model.GetTaskDatalistData, error) {
	secTaskList, err := db.GetDataList(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetTasksketchlist error,err:%+v", err)
		return nil, err
	}
	return secTaskList, nil
}
