package com.ghy.customer.service.impl;

import com.ghy.customer.domain.CustomerAddress;
import com.ghy.customer.mapper.CustomerAddressMapper;
import com.ghy.customer.service.CustomerAddressService;
import com.ghy.system.service.ISysAreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service
public class CustomerAddressServiceImpl implements CustomerAddressService {

    @Resource
    private CustomerAddressMapper customerAddressMapper;

    @Resource
    private ISysAreaService iSysAreaService;

    @Override
    public List<CustomerAddress> getCustomerAddressList(CustomerAddress customerAddress) {
        List<CustomerAddress> addressList = customerAddressMapper.getCustomerAddressList(customerAddress);
        for (CustomerAddress address : addressList) {
            address.setCountryName(iSysAreaService.selectById(address.getCountryId()).getAreaName());
            address.setCityName(iSysAreaService.selectById(address.getCityId()).getAreaName());
            address.setProvinceName(iSysAreaService.selectById(address.getProvinceId()).getAreaName());
        }
        return addressList;
    }

    @Override
    public int deleteByIds(String[] ids) {
        return customerAddressMapper.deleteByIds(ids);
    }

    @Override
    public int deleteByCustomerAddressId(Long customerAddressId) {
        return customerAddressMapper.deleteByCustomerAddressId(customerAddressId);
    }

    @Override
    public List<CustomerAddress> selectByCustomerId(Long customerId) {
        return customerAddressMapper.selectByCustomerId(customerId);
    }

    @Override
    public CustomerAddress selectByCustomerAddressId(Long customerAddressId) {
        return customerAddressMapper.selectByCustomerAddressId(customerAddressId);
    }

    @Override
    public int insertCustomerAddress(CustomerAddress customerAddress) {
        return customerAddressMapper.insertCustomerAddress(customerAddress);
    }

    @Override
    public int updateCustomerAddress(CustomerAddress customerAddress) {
        return customerAddressMapper.updateCustomerAddress(customerAddress);
    }

    @Override
    public CustomerAddress selectByCustomerAndAddress(Long customerId, Long provinceId, Long cityId, Long countryId, String address) {
        return customerAddressMapper.selectByCustomerAndAddress(customerId, provinceId, cityId, countryId, address);
    }
}
