package com.mosquito.project.dto;

import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@NoArgsConstructor
public class ActivityStatsResponse implements Serializable {

    private static final long serialVersionUID = 1L;

    private long pv;           // 页面访问次数
    private long uv;           // 独立访客（去重）
    private long participants; // 参与人数（完成目标用户）
    private long newUsers;     // 新增用户
    private long shares;      // 分享次数
    private double kFactor;   // K因子 = 总邀请数 / 新用户数
    private double cac;       // 用户获取成本 = 总奖励积分 / 新用户数
    private List<DailyStats> dailyStats; // 按天统计

    public ActivityStatsResponse(long pv, long uv, long participants, long newUsers, long shares,
                                 double kFactor, double cac, List<DailyStats> dailyStats) {
        this.pv = pv;
        this.uv = uv;
        this.participants = participants;
        this.newUsers = newUsers;
        this.shares = shares;
        this.kFactor = kFactor;
        this.cac = cac;
        this.dailyStats = dailyStats;
    }

    // 兼容旧构造函数
    public ActivityStatsResponse(long totalParticipants, long totalShares, List<DailyStats> dailyStats) {
        this.pv = 0;
        this.uv = 0;
        this.participants = totalParticipants;
        this.newUsers = totalParticipants;
        this.shares = totalShares;
        this.kFactor = totalParticipants > 0 ? (double) totalShares / totalParticipants : 0;
        this.cac = 0;
        this.dailyStats = dailyStats;
    }

    // Getters and Setters
    public long getPv() { return pv; }
    public void setPv(long pv) { this.pv = pv; }

    public long getUv() { return uv; }
    public void setUv(long uv) { this.uv = uv; }

    public long getParticipants() { return participants; }
    public void setParticipants(long participants) { this.participants = participants; }

    public long getNewUsers() { return newUsers; }
    public void setNewUsers(long newUsers) { this.newUsers = newUsers; }

    public long getShares() { return shares; }
    public void setShares(long shares) { this.shares = shares; }

    public double getkFactor() { return kFactor; }
    public void setkFactor(double kFactor) { this.kFactor = kFactor; }

    public double getCac() { return cac; }
    public void setCac(double cac) { this.cac = cac; }

    public List<DailyStats> getDailyStats() { return dailyStats; }
    public void setDailyStats(List<DailyStats> dailyStats) { this.dailyStats = dailyStats; }

    // 兼容旧方法
    public long getTotalParticipants() { return participants; }
    public long getTotalShares() { return shares; }
    public void setTotalParticipants(long value) { this.participants = value; }
    public void setTotalShares(long value) { this.shares = value; }

    @NoArgsConstructor
    public static class DailyStats implements Serializable {

        private static final long serialVersionUID = 1L;
        private String date;
        private int pv;
        private int uv;
        private int participants;
        private int newUsers;
        private int shares;
        private double kFactor;
        private double cac;

        public DailyStats(String date, int pv, int uv, int participants, int newUsers, int shares) {
            this.date = date;
            this.pv = pv;
            this.uv = uv;
            this.participants = participants;
            this.newUsers = newUsers;
            this.shares = shares;
            this.kFactor = participants > 0 ? (double) shares / participants : 0;
            this.cac = 0;
        }

        // 兼容旧构造函数
        public DailyStats(String date, int participants, int shares) {
            this.date = date;
            this.pv = 0;
            this.uv = 0;
            this.participants = participants;
            this.newUsers = participants;
            this.shares = shares;
            this.kFactor = participants > 0 ? (double) shares / participants : 0;
            this.cac = 0;
        }

        public String getDate() { return date; }
        public void setDate(String date) { this.date = date; }

        public int getPv() { return pv; }
        public void setPv(int pv) { this.pv = pv; }

        public int getUv() { return uv; }
        public void setUv(int uv) { this.uv = uv; }

        public int getParticipants() { return participants; }
        public void setParticipants(int participants) { this.participants = participants; }

        public int getNewUsers() { return newUsers; }
        public void setNewUsers(int newUsers) { this.newUsers = newUsers; }

        public int getShares() { return shares; }
        public void setShares(int shares) { this.shares = shares; }

        public double getkFactor() { return kFactor; }
        public void setkFactor(double kFactor) { this.kFactor = kFactor; }

        public double getCac() { return cac; }
        public void setCac(double cac) { this.cac = cac; }
    }
}
