package work_experience

import (
	"context"

	"wechat-api/internal/svc"
	"wechat-api/internal/types"
	"wechat-api/internal/utils/dberrorhandler"

    "github.com/suyuan32/simple-admin-common/msg/errormsg"

	"github.com/suyuan32/simple-admin-common/utils/pointy"
	"github.com/zeromicro/go-zero/core/logx"
)

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

func NewGetWorkExperienceByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWorkExperienceByIdLogic {
	return &GetWorkExperienceByIdLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetWorkExperienceByIdLogic) GetWorkExperienceById(req *types.IDReq) (*types.WorkExperienceInfoResp, error) {
	data, err := l.svcCtx.DB.WorkExperience.Get(l.ctx, req.Id)
	if err != nil {
		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
	}

	return &types.WorkExperienceInfoResp{
	    BaseDataInfo: types.BaseDataInfo{
            Code: 0,
            Msg:  errormsg.Success,
        },
        Data: types.WorkExperienceInfo{
            BaseIDInfo:    types.BaseIDInfo{
				Id:          &data.ID,
				CreatedAt:    pointy.GetPointer(data.CreatedAt.UnixMilli()),
				UpdatedAt:    pointy.GetPointer(data.UpdatedAt.UnixMilli()),
            },
			EmployeeId:	&data.EmployeeID,
			StartDate:	pointy.GetPointer(data.StartDate.UnixMilli()),
			EndDate:	pointy.GetPointer(data.EndDate.UnixMilli()),
			Company:	&data.Company,
			Experience:	&data.Experience,
        },
	}, nil
}

