package com.schoolinout.web.controller.api;

import com.schoolinout.common.core.domain.AjaxResult;
import com.schoolinout.common.core.domain.entity.SysDictData;
import com.schoolinout.common.utils.StringUtils;
import com.schoolinout.system.domain.dto.ApiParentDto;
import com.schoolinout.system.service.IApiParentService;
import com.schoolinout.system.service.ISysDictTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author sakura
 * @date 2024/1/9 17:17:17 Tue
 */
@Tag(name = "用户端-家长接口")
@RequestMapping("/app/parent")
@RestController
public class Api_ParentController {

    @Autowired
    private IApiParentService parentService;

    @Autowired
    private ISysDictTypeService dictTypeService;

    @Operation(summary = "家长登入")
    @PostMapping("/login")
    public AjaxResult parentLogin(@Validated @RequestBody ApiParentDto form) {
        // step1：校验验证码是否正确
        // step2：通过手机号去查询家长
        // step3：通过学号去查询学生
        // step4：返回登入成功的令牌
        return AjaxResult.success();
    }

    @Operation(summary = "家长注册")
    @PostMapping("/register")
    public AjaxResult parentRegister(@Validated @RequestBody ApiParentDto form) {
        // step1：校验验证码是否正确
        // step2：通过手机号去查询家长
        // step3：通过学号去查询学生
        // step4：返回登入成功的令牌
        return AjaxResult.success();
    }

    @Operation(summary = "发送手机号验证码")
    @PostMapping("/send/phone/code/{phone}")
    public AjaxResult sendPhoneCode(@PathVariable String phone) {
        // 发生验证码
        return AjaxResult.success();
    }

    @Operation(summary = "获取家长与学生关系列表")
    @GetMapping("/list/relation")
    public AjaxResult searcherRelation() {
        List<SysDictData> data = dictTypeService.selectDictDataByType("parent_relation");
        if (StringUtils.isNull(data)) {
            data = new ArrayList<>();
        }
        return AjaxResult.success(data);
    }
}
