# SPDX-FileCopyrightText: 2026 Yating Zhang
# SPDX-License-Identifier: MIT

using CSV,DataFrames, LinearAlgebra, Random
Random.seed!(314)    

# -------------- generate revenue, utility, and history-dependent effects -------
function gene_para(N,M,positive, mix, strong, ratio)
    r = round.(9*rand(N),digits = 2) .+ 1  
    r = -sort(-r)
    u = round.(2*rand(N).-1,digits = 3)
    beta = gene_beta(N,M,positive, mix,strong, ratio)
    return r, u, beta
end 

# -------- generate history-dependent effects --------------- 
function gene_beta(N,M,positive, mix,strong, ratio)
    # addiction case [0,1]
    if positive  == 1
        beta = round.(rand(N,M),digits = 2)
    else 
        # pure satiaiton case 
        if mix==0  
            if strong ==1 # strong [-2,-1] 
                beta = round.(rand(N,M).-2,digits = 3)
            else  # weak [-1,0]
                beta = round.(rand(N,M).-1,digits = 3)
            end 
        # mix case 
        else  
            beta = zeros(N,M) 
            for i in 1:N 
                rv = rand() 
                if rv<= ratio # positve effects 
                    beta[i,:] = round.(rand(M),digits = 3)  
                else  # negative effects 
                    if strong == 1
                        beta[i,:] = round.(rand(M).-2,digits = 3)
                    else
                        beta[i,:] = round.(rand(M).-1,digits = 3)
                    end 
                end  
            end 
        end 
    end 
    return beta 
end 


# ------------- change a matrix to dataframe form ------------------
function tupe2mat(a)
    n = length(a[1])
    m = ones(length(a), n)
    for i in 1:length(a)
         m[i,:] = [t for t in a[i]]
    end
    return m
end