package com.seer.teach.iot.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.common.convert.ProvinceConvert;
import com.seer.teach.common.entity.ProvinceEntity;
import com.seer.teach.common.resp.CityResp;
import com.seer.teach.common.resp.ProvinceResp;
import com.seer.teach.common.service.RegionAddressService;
import com.seer.teach.common.service.ProvinceService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 *
 * </p >
 *
 * @author Captain
 * @since 2025-08-13 15:00
 */
@RequestMapping("/iot/region")
@RestController
@Tag(name = "地域")
@Validated
@RequiredArgsConstructor
@SaCheckLogin
public class RegionController {

    private final RegionAddressService regionAddressService;

    private final ProvinceService provinceService;

    @GetMapping("/provinces")
    @LogPrint
    @Operation(summary = "省")
    public ResultBean<List<ProvinceResp>> provinces(){
        List<ProvinceEntity> list = provinceService.list();
        List<ProvinceResp> results = ProvinceConvert.INSTANCE.toProvinceRespList(list);
        return ResultBean.success(results);
    }

    @GetMapping("/citys/{provinceId}")
    @LogPrint
    @Operation(summary = "通过省份ID获取城市列表")
    public ResultBean<List<CityResp>> citys(@PathVariable("provinceId") @NotNull(message = "省份ID不可为空") Integer provinceId) {
        List<CityResp> cities = regionAddressService.getCitiesByProvinceId(provinceId);
        return ResultBean.success(cities);
    }

}
