package com.fs.ad.service.impl;

import java.util.Collections;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.ad.domain.AdAccount;
import com.fs.ad.mapper.AdAccountMapper;
import com.fs.ad.service.IAdAccountService;
import com.fs.common.utils.DateUtils;
import lombok.AllArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.ad.mapper.AdIqiyiAccountMapper;
import com.fs.ad.domain.AdIqiyiAccount;
import com.fs.ad.service.IAdIqiyiAccountService;

/**
 * 爱奇艺广告账号Service业务层处理
 * 
 * @author fs
 * @date 2025-03-0
 */
@Service
@AllArgsConstructor
public class AdIqiyiAccountServiceImpl extends ServiceImpl<AdIqiyiAccountMapper, AdIqiyiAccount> implements IAdIqiyiAccountService {

    private final IAdAccountService adAccountService;

    /**
     * 查询爱奇艺广告账号
     * 
     * @param id 爱奇艺广告账号主键
     * @return 爱奇艺广告账号
     */
    @Override
    public AdIqiyiAccount selectAdIqiyiAccountById(Long id)
    {
        return baseMapper.selectAdIqiyiAccountById(id);
    }

    /**
     * 查询爱奇艺广告账号列表
     * 
     * @param adIqiyiAccount 爱奇艺广告账号
     * @return 爱奇艺广告账号
     */
    @Override
    public List<AdIqiyiAccount> selectAdIqiyiAccountList(AdIqiyiAccount adIqiyiAccount)
    {
        return baseMapper.selectAdIqiyiAccountList(adIqiyiAccount);
    }

    /**
     * 新增爱奇艺广告账号
     * 
     * @param adIqiyiAccount 爱奇艺广告账号
     * @return 结果
     */
    @Override
    public int insertAdIqiyiAccount(AdIqiyiAccount adIqiyiAccount)
    {
        adIqiyiAccount.setCreateTime(DateUtils.getNowDate());
        int insert = baseMapper.insert(adIqiyiAccount);
        AdAccount adAccount = new AdAccount();
        adAccount.setName(adIqiyiAccount.getAccountName());
        adAccount.setType(2);
        adAccount.setLinkId(adIqiyiAccount.getId());
        adAccountService.save(adAccount);
        return insert;
    }

    /**
     * 修改爱奇艺广告账号
     * 
     * @param adIqiyiAccount 爱奇艺广告账号
     * @return 结果
     */
    @Override
    public int updateAdIqiyiAccount(AdIqiyiAccount adIqiyiAccount)
    {
        adIqiyiAccount.setUpdateTime(DateUtils.getNowDate());

        AdAccount adAccount = adAccountService.selectByLinkId(adIqiyiAccount.getId());
        adAccount.setName(adIqiyiAccount.getAccountName());
        adAccountService.updateById(adAccount);
        return baseMapper.updateAdIqiyiAccount(adIqiyiAccount);
    }

    /**
     * 批量删除爱奇艺广告账号
     * 
     * @param ids 需要删除的爱奇艺广告账号主键
     * @return 结果
     */
    @Override
    public int deleteAdIqiyiAccountByIds(Long[] ids)
    {
        adAccountService.deleteByLinkIds(2, ids);
        return baseMapper.deleteAdIqiyiAccountByIds(ids);
    }

    /**
     * 删除爱奇艺广告账号信息
     * 
     * @param id 爱奇艺广告账号主键
     * @return 结果
     */
    @Override
    public int deleteAdIqiyiAccountById(Long id)
    {
        adAccountService.deleteByLinkId(2, id);
        return baseMapper.deleteAdIqiyiAccountById(id);
    }

    @Override
    public List<AdIqiyiAccount> listAll() {
        return super.list();
    }
}
