package com.template.controller;


import com.seewo.open.sdk.DefaultSeewoClient;
import com.seewo.open.sdk.SeewoClient;
import com.seewo.open.sdk.auth.Account;
import com.template.api.SmartAttendanceControllerAPI;
import com.template.config.SeewoConfig;
import com.template.model.pojo.*;
import com.template.model.result.CommonResult;
import com.template.model.seewo.PersonalLeaveListSchoolPeriodRecordsParam;
import com.template.model.seewo.PersonalLeaveListSchoolPeriodRecordsRequest;
import com.template.model.seewo.PersonalLeaveListSchoolPeriodRecordsResult;
import org.springframework.validation.BindingResult;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 楼栋表 前端控制器
 * </p>
 *
 * @author ceshi
 * @since 2023-12-25
 */
@RestController
public class SmartAttendanceController implements SmartAttendanceControllerAPI {

    @Resource
    private SeewoConfig seewoConfig;

    @Override
    public CommonResult insertSmartAttendance(SmartAttendance smartApply, BindingResult bindingResult) {
        return null;
    }

    @Override
    public CommonResult updateSmartAttendanceById(SmartAttendance ra, BindingResult bindingResult) {
        return null;
    }

    @Override
    public CommonResult queryPageSmartAttendances(int currentPage, int pageCount, String name) {
        return null;
    }

    @Override
    public CommonResult deleteSmartAttendanceById(int id) {
        return null;
    }

    @Override
    public CommonResult queryLeaveRecords() {
        //初始化客户端
        SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
        PersonalLeaveListSchoolPeriodRecordsParam param = new PersonalLeaveListSchoolPeriodRecordsParam();
        //请求体，MimeType为 application/json
        PersonalLeaveListSchoolPeriodRecordsParam.RequestBody requestBody = PersonalLeaveListSchoolPeriodRecordsParam.RequestBody.builder()
                .build();
        param.setRequestBody(requestBody);
        //query
        PersonalLeaveListSchoolPeriodRecordsParam.Query query = PersonalLeaveListSchoolPeriodRecordsParam.Query.builder()
                .schoolUid(seewoConfig.getSchoolId())//学校ID
                .startDate("2024-01-05")//开始日期
                .endDate("2024-01-05")//结束日期
                .page(1)//当前页
                .pageSize(20)//分页条数
                .appId(seewoConfig.getAppId())
                .build();
        requestBody.setQuery(query);
        param.setRequestBody(requestBody);
        PersonalLeaveListSchoolPeriodRecordsRequest request = new PersonalLeaveListSchoolPeriodRecordsRequest(param);
        System.out.println("入参：" +request);
        //如果想要调用沙箱环境，请通过设置 request 对象的 serverUrl 属性，如：
        //request.setServerUrl("https://openapi.test.seewo.com")
        //执行请求，如果想获取到com.seewo.open.sdk.HttpResponse对象，请调用 seewoClient.execute 方法
        PersonalLeaveListSchoolPeriodRecordsResult result = seewoClient.invoke(request);
        System.out.println("出参：" +result);

        return CommonResult.ok("操作成功");
    }
}

