package io.controller;

import io.common.utils.Result;
import io.modules.item.dto.AreaDTO;
import io.modules.item.dto.CityDTO;
import io.modules.item.dto.ProvinceDTO;
import io.modules.item.dto.ProvinceTree;
import io.modules.item.service.AreaService;
import io.modules.item.service.CityService;
import io.modules.item.service.ProvinceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import java.util.List;
import java.util.Map;

/**
 * 地区信息
 */
@RestController
@RequestMapping("api/area")
@Tag(name="地区信息")
@CrossOrigin
public class AreaController {
    @Autowired
    private ProvinceService provinceService;

    @Autowired
    private CityService cityService;

    @Autowired
    private AreaService areaService;


    @GetMapping("tree")
    @Operation(summary = "结构树")
    public Result<List<ProvinceTree>> tree(){
        List<ProvinceTree> page = provinceService.tree();
        return new Result<List<ProvinceTree>>().ok(page);
    }

    @GetMapping("province")
    @Operation(summary = "省份分页")
    @Parameters({
            @Parameter(name = "provinceId", description = "城市编号", in = ParameterIn.QUERY, required = true, ref = "String")    })
    public Result<List<ProvinceDTO>> ProvinceList(@Parameter(hidden = true) @RequestParam Map<String, Object> params){
        List<ProvinceDTO> page = provinceService.list(params);
        return new Result<List<ProvinceDTO>>().ok(page);
    }

    @GetMapping("city")
    @Operation(summary = "城市分页")
    @Parameters({
            @Parameter(name = "cityId", description = "城市编号", in = ParameterIn.QUERY, required = true, ref = "String"),
            @Parameter(name = "father", description = "父编号", in = ParameterIn.QUERY, required = true, ref = "String"),
    })
    public Result<List<CityDTO>> CityList(@Parameter(hidden = true) @RequestParam Map<String, Object> params){
        List<CityDTO> page = cityService.list(params);
        return new Result<List<CityDTO>>().ok(page);
    }

    @GetMapping("area")
    @Operation(summary = "区域分页")
    @Parameters({
            @Parameter(name = "areaId", description = " 区域编号", in = ParameterIn.QUERY, required = true, ref = "String"),
            @Parameter(name = "father", description = " 父编号", in = ParameterIn.QUERY, required = true, ref = "String"),
    })
    public Result<List<AreaDTO>> AreaList(@Parameter(hidden = true) @RequestParam Map<String, Object> params){
        List<AreaDTO> page = areaService.list(params);
        return new Result<List<AreaDTO>>().ok(page);
    }

}
