package com.lesingle.modules.pub.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lesingle.common.enums.CommonStatus;
import com.lesingle.modules.ugc.entity.UgcTag;
import com.lesingle.modules.ugc.mapper.UgcTagMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class PublicTagService {

    private final UgcTagMapper ugcTagMapper;

    /**
     * 获取所有启用标签
     */
    public List<UgcTag> listTags() {
        return ugcTagMapper.selectList(
                new LambdaQueryWrapper<UgcTag>()
                        .eq(UgcTag::getStatus, CommonStatus.ENABLED.getValue())
                        .orderByAsc(UgcTag::getSort));
    }

    /**
     * 获取热门标签
     */
    public List<UgcTag> getHotTags() {
        return ugcTagMapper.selectList(
                new LambdaQueryWrapper<UgcTag>()
                        .eq(UgcTag::getStatus, CommonStatus.ENABLED.getValue())
                        .orderByDesc(UgcTag::getUsageCount)
                        .last("LIMIT 20"));
    }
}
