package com.ylx.area.controller;

import com.ylx.common.core.domain.R;
import com.ylx.area.service.AreaService;
import com.ylx.massage.service.IMaTechnicianService;
import com.ylx.area.domain.vo.CityVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类描述：用户首页选择地区
 *
 * @author Administrator
 * @version 1.0
 * @date 2026/6/2 9:33
 */
@Slf4j
@RestController
@Api(tags = {"用户首页选择地区"})
@RequestMapping("/customer/city")
public class CustomerCityController {
    @Resource(name = "areaService")
    private AreaService areaService;

    @Autowired
    private IMaTechnicianService iMaTechnicianService;
    /**
     * 首页-城市列表
     *
     * @return
     */
    @ApiOperation(value="首页-城市列表", notes="首页-城市列表")
    @PostMapping(value = "/getCityList")
    public R<List<CityVo>> getCityList() {
        try {
            List<CityVo> list = areaService.getHomeList();
            return R.ok(list);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.fail("接口异常请重试!");
        }
    }

    @ApiOperation(value="首页选中的城市是否有开通服务", notes="首页选中的城市是否有开通服务;true表示该城市有开通服务")
    @GetMapping(value = "/isHasMerchantCity")
    public R<Boolean> isHasMerchantCity(@RequestParam("areaCode") String areaCode) {
            return R.ok(iMaTechnicianService.isHasMerchantCity(areaCode));
    }

    /**
     * 首页-城市列表查询
     *
     * @param name
     * @return Result
     */
    @ApiOperation(value="首页-城市列表查询", notes="首页-城市列表查询")
    @GetMapping(value = "/getCityByName")
    public R<List<CityVo>> getCityByName(@RequestParam(value = "name",required = false) String name) {
        try {
            List<CityVo> list = areaService.getCityName(name);
            return R.ok(list);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.fail("接口异常请重试!");
        }
    }
}