package com.leromro.core.controller;

import java.util.List;


import com.leromro.common.utils.SecurityUtils;
import com.leromro.core.domain.Address;
import com.leromro.core.service.AddressService;
import io.swagger.annotations.Api;
import com.leromro.common.core.domain.R;
import io.swagger.annotations.ApiOperation;
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;


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

    /**
     * 查询受服务地址列表
     * 已测试
     */
    @ApiOperation("查询受服务地址列表")
   // @PreAuthorize("@ss.hasPermi('system:address:list')")
    @GetMapping("/list")
    public R<List<Address>> selectAddresslist()
    {
        Long userId = SecurityUtils.getUserId();
        List<Address> list = addressService.selectLAddressList(userId);
        return R.ok(list);
    }

    /**
     * 获取受服务地址详细信息
     * 未测试
     */
    @ApiOperation("获取受服务地址详细信息")
   // @PreAuthorize("@ss.hasPermi('system:address:query')")
    @GetMapping(value = "/{addressId}")
    public R<Address> getAddressInfo(@PathVariable("addressId") Long addressId)
    {
        return R.ok(addressService.selectLAddressByAddressId(addressId));
    }

    /**
     * 新增受服务地址
     * 已测试
     */
    @ApiOperation("新增受服务地址")
 // @PreAuthorize("@ss.hasPermi('system:address:add')")
    @Log(title = "受服务地址", businessType = BusinessType.INSERT)
    @PutMapping("/newAddress")
    public AjaxResult newAddress(@RequestBody Address address)
    {   Long userId = SecurityUtils.getUserId();
        address.setUserId(userId);
        return toAjax(addressService.insertLAddress(address));
    }

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

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