package com.tourism.webadmin.app.website.controller;

import com.tourism.common.core.constant.ErrorCodeEnum;
import com.tourism.common.core.object.MyPageData;
import com.tourism.common.core.object.ResponseResult;
import com.tourism.common.core.object.TokenData;
import com.tourism.webadmin.app.website.dto.PageDto;
import com.tourism.webadmin.app.website.service.JobRecordService;
import com.tourism.webadmin.back.model.TourUser;
import com.tourism.webadmin.back.service.TourUserService;
import com.tourism.webadmin.back.vo.TourBookInfoVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "劳务记录接口")
@Slf4j
@RestController
@Validated
@RequestMapping("/website/jobRecord")
public class JobRecordController {
    @Autowired
    private TourUserService tourUserService;
    @Autowired
    private JobRecordService jobRecordService;

    /**
     * 列出符合条件的劳务记录列表。
     *
     * @return 应答结果对象，包含查询结果集。
     */
    @GetMapping("/list")
    public ResponseResult<MyPageData<TourBookInfoVo>> list(PageDto pageDto) {
        TokenData tokenData = TokenData.takeFromRequest();
        if(tokenData == null){
            return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED);
        }
        Long userId = tokenData.getUserId();
        TourUser tourUser = tourUserService.getById(userId);
        if(tourUser == null){
            return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED);
        }
        MyPageData<TourBookInfoVo> tourBookInfoVoMyPageData = jobRecordService.jobRecordList(tourUser.getMobile(), pageDto);
        return ResponseResult.success(tourBookInfoVoMyPageData);
    }
}
