package service

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

var LocalTask *localtask

type localtask struct {
}

func (*localtask) GetLocalRecruitTime(ctx context.Context, request http_model.GetLocalRecruitTimeRequest) (*http_model.GetLocalRecruitTimeResponse, error) {
	recruit, err := db.GetLocalRecruittime(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[localtask service] call GetLocalRecruitTime error,err:%+v", err)
		return nil, err
	}
	return recruit, nil
}

func (*localtask) GetLocalTalentstatusNum(ctx context.Context, request http_model.GetLocalTalentstatusNumRequest) (*http_model.GetLocalTalentstatusNumResponse, error) {
	statusnum, err := db.GetLocalTalentstatusNumCount(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[localtask service] call GetLocalTalentstatusNum error,err:%+v", err)
		return nil, err
	}
	return statusnum, nil
}

func (*localtask) GetLocalTalentstatusCount(ctx context.Context, request http_model.GetLocalTalentstatusCountRequest) (*http_model.GetLocalTalentstatusCountResponse, error) {
	statusnum, err := db.GetLocalTalentstatusCountNum(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[localtask service] call GetTalentstatusNum error,err:%+v", err)
		return nil, err
	}
	return statusnum, nil
}

func (*localtask) GetLocalList(ctx context.Context, request http_model.GetLocalTaskListRequest) (*http_model.GetLocalTaskListData, error) {
	localTaskList, err := db.GetLocallifetaskList(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[localtask service] call GetLocalTaskList error,err:%+v", err)
		return nil, err
	}
	return localTaskList, nil
}

func (*localtask) PassCoop(ctx context.Context, request http_model.PasslocalTaskCoopRequest) (*http_model.PassSecTaskCoopData, error) {
	_, err := db.PassLocalTaskCoop(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[localtask service] call PassCoop error,err:%+v", err)
		return nil, err
	}

	selectionListData := http_model.PassSecTaskCoopData{}

	return &selectionListData, nil
}

func (*localtask) RefuseCoop(ctx context.Context, request http_model.RefuselocalTaskCoopRequest) (*http_model.PasslocalTaskCoopData, error) {

	_, err := db.RefuseLocalTaskCoop(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[localtask] call RefuseCoop error,err:%+v", err)
		return nil, err
	}

	projectListData := http_model.PasslocalTaskCoopData{}

	return &projectListData, nil
}

func (*localtask) Data(ctx context.Context, Project http_model.LocallifeDataRequest) (*http_model.LocallifeDataResponse, error) {
	projectdata, err := db.GetLocallifeData(ctx, Project)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[localtask service] call Data error,err:%+v", err)
		return nil, err
	}
	return &projectdata, nil
}

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

func (*localtask) GetLocalTasksketchlist(ctx context.Context, request http_model.LocalTasksketchlistRequest) (*http_model.GetsketchlocaltaskListData, error) {
	secTaskList, err := db.GetLocalSketchList(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[localtask service] call GetLocalTasksketchlist error,err:%+v", err)
		return nil, err
	}
	return secTaskList, nil
}

func (*localtask) GetLocalPreLinkList(ctx context.Context, request http_model.LocalPreLinkListRequest) (*http_model.GetLocalPreLinkListData, error) {
	secTaskList, err := db.GetLocalPreLinkList(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 (*localtask) GetLocalTaskLinklist(ctx context.Context, request http_model.LocalTaskLinklistRequest) (*http_model.GetLocalTaskLinkListData, error) {
	secTaskList, err := db.GetLocalLinkList(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 (*localtask) GetLocalPreDataList(ctx context.Context, request http_model.LocalPreDataListRequest) (*http_model.GetLocalPreDataListData, error) {
	secTaskList, err := db.GetLocalPreDataList(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 (*localtask) GetLocalTaskDatalist(ctx context.Context, request http_model.LocalTaskDatalistRequest) (*http_model.GetLocalTaskDatalistData, error) {
	secTaskList, err := db.GetLocalDataList(ctx, request)
	if err != nil {
		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetTasksketchlist error,err:%+v", err)
		return nil, err
	}
	return secTaskList, nil
}
