package com.leromro.core.controller;

import java.util.List;

import com.leromro.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.leromro.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.leromro.common.annotation.Log;
import com.leromro.common.core.controller.BaseController;
import com.leromro.common.core.domain.AjaxResult;
import com.leromro.common.enums.BusinessType;
import com.leromro.core.domain.Address;
import com.leromro.core.service.IAddressService;
import com.leromro.common.core.page.TableDataInfo;

/**
 * 受服务地址Controller
 * 
 * @author ruoyi
 * @date 2025-04-18
 */
@RestController
@Api(tags = "受服务地址")
@RequestMapping("/core/user/address")
public class AddressController extends BaseController
{
    @Autowired
    private IAddressService addressService;

    /**
     * 查询受服务地址列表
     * 传入传入userI
     */
    @ApiOperation("查询自己的受服务地址列表")
/*    @PreAuthorize("@ss.hasPermi('core:address:list')")*/
    @GetMapping("/list")
    public TableDataInfo<Address> list(@RequestBody Address address)
    {
        startPage();
        Long userId = SecurityUtils.getUserId();
        address.setUserId(userId);
        List<Address> list = addressService.selectAddressList(address);
        return getDataTable(list);
    }

    /**
     * 查询受服务地址列表
     */
    @ApiOperation("设置默认地址")
/*    @PreAuthorize("@ss.hasPermi('core:address:list')")*/
    @Log(title = "设置默认地址", businessType = BusinessType.UPDATE)
    @GetMapping("/setDefaultAddress")
    public AjaxResult setDefaultAddress(@RequestBody Address address)
    {
        return addressService.setDefaultAddress(address);
    }
    /**
     * 查询受默认服务地址列表
     */
    @ApiOperation("查询默认地址")
/*    @PreAuthorize("@ss.hasPermi('core:address:list')")*/

    @Log(title = "查询默认地址")
    @GetMapping("/selectDefaultAddress")
    public R<Address> selectDefaultAddress()
    {
        return addressService.selectDefalutAddress();
    }

    /**
     * 获取受服务地址详细信息
     */
    @ApiOperation("获取受服务地址详细信息 回显")
/*    @PreAuthorize("@ss.hasPermi('core:address:query')")*/
    @GetMapping(value = "/{addressId}")
    public R<Address> getInfo(@PathVariable("addressId") Long addressId)
    {
        return R.ok(addressService.selectAddressByAddressId(addressId));
    }

    /**
     * 新增受服务地址
     */
    @ApiOperation("新增受服务地址")
/*    @PreAuthorize("@ss.hasPermi('core:address:add')")*/
    @Log(title = "新增受服务地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Address address)
    {
        return toAjax(addressService.insertAddress(address));
    }

    /**
     * 修改受服务地址
     */
    @ApiOperation("修改受服务地址")
   /* @PreAuthorize("@ss.hasPermi('core:address:edit')")*/
    @Log(title = "受服务地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Address address)
    {
        return toAjax(addressService.updateAddress(address));
    }

    /**
     * 删除受服务地址
     */
    @ApiOperation("删除受服务地址")
    /*@PreAuthorize("@ss.hasPermi('core:address:remove')")*/
    @Log(title = "受服务地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{addressIds}")
    public R<Integer> remove(@PathVariable Long[] addressIds)
    {
        return R.ok(addressService.deleteAddressByAddressIds(addressIds));
    }

    /**
     * 导出受服务地址列表
     */
    /*@ApiOperation("导出受服务地址列表")
     *//*    @PreAuthorize("@ss.hasPermi('core:address:export')")*//*
    @Log(title = "受服务地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Address address)
    {
        List<Address> list = addressService.selectAddressList(address);
        ExcelUtil<Address> util = new ExcelUtil<Address>(Address.class);
        util.exportExcel(response, list, "受服务地址数据");
    }*/
}
