package com.starry.admin.modules.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.modules.shop.mapper.ShopUiSettingMapper;
import com.starry.admin.modules.shop.module.entity.ShopUiSettingEntity;
import com.starry.admin.modules.shop.service.IShopUiSettingService;
import java.util.Objects;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 店铺设置Service业务层处理
 *
 * @author admin
 * @since 2025-06-11
 */
@Service
public class ShopUiSettingServiceImpl extends ServiceImpl<ShopUiSettingMapper, ShopUiSettingEntity>
        implements
            IShopUiSettingService {
    @Resource
    private ShopUiSettingMapper shopUiSettingMapper;

    /**
     * 查询店铺设置
     *
     * @return 店铺设置
     */
    @Override
    public ShopUiSettingEntity selectShopUiSettingInfo() {
        LambdaQueryWrapper<ShopUiSettingEntity> wrapper = Wrappers.lambdaQuery(ShopUiSettingEntity.class);
        ShopUiSettingEntity setting = this.baseMapper.selectOne(wrapper, false);
        if (Objects.nonNull(setting)) {
            return setting;
        } else {
            setting = new ShopUiSettingEntity();
            setting.setSettingConfig(null);
            this.baseMapper.insert(setting);
        }
        return setting;
    }

    /**
     * 修改店铺设置
     *
     * @param shopUiSetting
     *            店铺设置
     * @return 结果
     */
    @Override
    public boolean update(ShopUiSettingEntity shopUiSetting) {
        return updateById(shopUiSetting);
    }
}
