package com.sptg.permissions.biz.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.permissions.api.dto.AreaDto;
import com.sptg.permissions.api.entity.AppArea;
import com.sptg.permissions.api.entity.Area;
import com.sptg.permissions.api.feigns.AreaFeign;
import com.sptg.permissions.biz.service.AreaServiceInterface;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * title: AreaController
 * package: com.sptg.permissions.biz.controller
 * description: 全国省市区街道-控制器
 *
 *                  
 *                
 */
@RestController
@RequiredArgsConstructor
public class AreaController implements AreaFeign {

    private final AreaServiceInterface areaServiceInterface;


    @Override
    @GetMapping(value = "/area/getSubList/{parentCode}")
    public List<Area> getSubList(@PathVariable(value = "parentCode")Serializable parentCode) {
        return this.areaServiceInterface.getSubList(parentCode);
    }

    @Override
    @GetMapping(value = "/area/selectByCode/{code}")
    public Area selectByCode(@PathVariable(value = "code") Serializable code) {
        return this.areaServiceInterface.selectByCode(code);
    }

    @Override
    @PostMapping(value = "/area/getListByIds")
    public List<Area> getListByIds(@RequestBody List<Long> idList) {
        List<Area> list = new ArrayList<>(idList.size());
        idList.forEach(id -> {
            Area area = this.areaServiceInterface.selectByCode(id);
            if (null != area) {
                list.add(area);
            }
        });
        return list;
    }

    @Override
    @PostMapping(value = "/area/selectByNameAndLayer")
    public Map<String ,Object> selectByNameAndLayer(@RequestBody AreaDto dto) {
        return this.areaServiceInterface.selectByNameAndLayer(dto);
    }

    @Override
    @GetMapping(value = "/area/getCityAndProvinceByName")
    public List<Area> getCityAndProvinceByName(@RequestParam(value = "name") String name){
        return this.areaServiceInterface.selectCityAndProvinceByName(name);
    }
    @Override
    @GetMapping(value = "/area/getAll")
    public List<AppArea> selectAll() {
        return areaServiceInterface.selectAll();
    }
    @Override
    @PostMapping(value = "/area/pagingQuery")
    public ResultBean<Page<Area>> pagingQuery(@RequestBody AreaDto areaDto) {
        return this.areaServiceInterface.pagingQuery(areaDto);
    }
    @Override
    @PostMapping(value = "/area/addArea")
    public ResultBean<Boolean> addArea(@RequestBody AreaDto areaDto) {
        return this.areaServiceInterface.addArea(areaDto);
    }
    @Override
    @GetMapping(value = "/area/getById/{id}")
    public Area getById(@PathVariable(value = "id") Serializable id) {
        return this.areaServiceInterface.getById(id);
    }
    @Override
    @PostMapping(value = "/area/delete")
    public ResultBean<Boolean> delete(@RequestBody Area area) {
        return this.areaServiceInterface.delete(area);
    }
}
