package com.ttstd.signaling.service;

import com.ttstd.signaling.model.AbuseReport;
import com.ttstd.signaling.repository.AbuseReportRepository;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 骚扰举报服务（P2 风控）：被控端可对骚扰自己的主控端账号提交举报。
 */
@Service
public class AbuseReportService {

    private final AbuseReportRepository repository;

    public AbuseReportService(AbuseReportRepository repository) {
        this.repository = repository;
    }

    public AbuseReport report(String deviceUid, String reportedUserId, String reason) {
        AbuseReport report = new AbuseReport(deviceUid, reportedUserId, reason);
        return repository.save(report);
    }

    public List<AbuseReport> listPending() {
        return repository.findByStatus(AbuseReport.ReportStatus.PENDING);
    }

    public List<AbuseReport> listByReportedUser(String reportedUserId) {
        return repository.findByReportedUserId(reportedUserId);
    }

    public void handle(Long id, AbuseReport.ReportStatus status) {
        repository.findById(id).ifPresent(r -> {
            r.setStatus(status);
            repository.save(r);
        });
    }
}
