package com.usky.sas.controller.web;

import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.sas.service.SasOneStandardSixRealitiesService;
import com.usky.sas.service.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 一标六实接口
 *
 * 对应 API 文档：
 * /prod-api/service-sas/one-standard-six-realities/...
 */
@RestController
@RequestMapping("/one-standard-six-realities")
public class SasOneStandardSixRealitiesController {

    @Autowired
    private SasOneStandardSixRealitiesService sasOneStandardSixRealitiesService;

    /**
     * 1.1 查询实有力量信息
     */
    @GetMapping("/power")
    public ApiResult<CommonPage<PowerListItem>> power(OneStandardSixRealitiesPageRequest request) {
        return ApiResult.success(sasOneStandardSixRealitiesService.powerPage(request));
    }

    /**
     * 1.2 同步实有力量
     */
    @PostMapping("/powerSync")
    public ApiResult<Integer> powerSync() {
        return ApiResult.success(sasOneStandardSixRealitiesService.syncPower());
    }

    /**
     * 2.1 查询实有设施信息
     */
    @GetMapping("/facility")
    public ApiResult<CommonPage<FacilityListItem>> facility(OneStandardSixRealitiesPageRequest request) {
        return ApiResult.success(sasOneStandardSixRealitiesService.facilityPage(request));
    }

    /**
     * 2.2 同步实有设施
     */
    @PostMapping("/facilitySync")
    public ApiResult<Integer> facilitySync() {
        return ApiResult.success(sasOneStandardSixRealitiesService.syncFacility());
    }

    /**
     * 3.1 查询出入口信息
     */
    @GetMapping("/entrance")
    public ApiResult<CommonPage<EntranceListItem>> entrance(OneStandardSixRealitiesPageRequest request) {
        return ApiResult.success(sasOneStandardSixRealitiesService.entrancePage(request));
    }

    /**
     * 3.2 同步出入口
     */
    @PostMapping("/entranceSync")
    public ApiResult<Integer> entranceSync() {
        return ApiResult.success(sasOneStandardSixRealitiesService.syncEntrance());
    }

    /**
     * 4.1 查询区域信息
     */
    @GetMapping("/area")
    public ApiResult<CommonPage<AreaListItem>> area(OneStandardSixRealitiesPageRequest request) {
        return ApiResult.success(sasOneStandardSixRealitiesService.areaPage(request));
    }

    /**
     * 4.2 同步区域信息
     */
    @PostMapping("/areaSync")
    public ApiResult<Integer> areaSync() {
        return ApiResult.success(sasOneStandardSixRealitiesService.syncArea());
    }

    /**
     * 5.1 查询房屋信息
     */
    @GetMapping("/house")
    public ApiResult<CommonPage<HouseListItem>> house(OneStandardSixRealitiesPageRequest request) {
        return ApiResult.success(sasOneStandardSixRealitiesService.housePage(request));
    }

    /**
     * 5.2 同步房屋信息
     * @param buildingCode 区域编码（楼栋编码），可选，传入时仅同步该楼栋下的房屋
     */
    @PostMapping("/houseSync")
    public ApiResult<Integer> houseSync(@RequestParam(required = false) String buildingCode) {
        return ApiResult.success(sasOneStandardSixRealitiesService.syncHouse(buildingCode));
    }

    /**
     * 6.1 查询地块信息
     */
    @GetMapping("/village")
    public ApiResult<CommonPage<VillageListItem>> village(OneStandardSixRealitiesPageRequest request) {
        return ApiResult.success(sasOneStandardSixRealitiesService.villagePage(request));
    }

    /**
     * 6.2 同步地块信息
     */
    @PostMapping("/villageSync")
    public ApiResult<Integer> villageSync() {
        return ApiResult.success(sasOneStandardSixRealitiesService.syncVillage());
    }

    /**
     * 6.3 设置默认地块
     */
    @PutMapping("/villageDefault/{villageCode}")
    public ApiResult<Void> setVillageDefault(@PathVariable("villageCode") String villageCode) {
        sasOneStandardSixRealitiesService.setVillageDefault(villageCode);
        return ApiResult.success();
    }
}

