package mkt_part_time_user

import (
	"context"
	"git.i2edu.net/i2/i2-bill-api/model"

	"git.i2edu.net/i2/i2-bill-api/internal/svc"
	"git.i2edu.net/i2/i2-bill-api/internal/types"

	"git.i2edu.net/i2/go-zero/core/logx"
)

type PartTimeUserGetLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPartTimeUserGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) PartTimeUserGetLogic {
	return PartTimeUserGetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PartTimeUserGetLogic) PartTimeUserGet() (*types.Response, error) {
	// todo: add your logic here and delete this line
	userId := l.svcCtx.GetUserIdByJwt(l.ctx)
	partTimeUser := new(model.I2billMktPartTimeUser)
	_, err := l.svcCtx.DB.Where("user_id = ? and del_flag = 0", userId).Get(partTimeUser)
	if err != nil {
		logx.Error(err.Error())
		return &types.Response{Code: 500, Msg: err.Error(), Data: nil}, nil
	}
	if partTimeUser.Id == 0 {
		return &types.Response{Code: 200, Msg: "你还没有申请成为兼职人员！", Data: nil}, nil
	}
	return &types.Response{Code: 200, Msg: "", Data: partTimeUser}, nil
}
