import type { Citation } from './utils/wsFrames';
import type { PromptRating } from './utils/promptFeedback';

export type PromptFeedbackState = {
    rating: PromptRating;
    reason?: string | null;
    comment?: string | null;
};

/* Classes for the project */
export interface ConversationPromptType {
    id: number,
    message: string, 
    user_created: boolean,
    created_timestamp?: Date,
    created?: Date | string,
    tokens_in?: number | null,
    tokens_out?: number | null,
    citations?: Citation[],
    feedback?: PromptFeedbackState | null,
}

export class ConversationPrompt{
    id: number | undefined;
    message: string = '';
    user_created: boolean = false;
    created_timestamp: Date = new Date();
    tokens_in: number | null = null;
    tokens_out: number | null = null;
    citations: Citation[] = [];
    feedback: PromptFeedbackState | null = null;

    constructor(initializer?: any){
        if(!initializer) return;
        if (initializer.id) this.id = initializer.id;
        if (initializer.message) this.message = initializer.message;
        if (initializer.user_created) this.user_created = initializer.user_created;
        if (initializer.created_timestamp) this.created_timestamp = initializer.created_timestamp;
        else if (initializer.created) this.created_timestamp = new Date(initializer.created);
        if (initializer.tokens_in !== undefined) this.tokens_in = initializer.tokens_in;
        if (initializer.tokens_out !== undefined) this.tokens_out = initializer.tokens_out;
        if (Array.isArray(initializer.citations)) this.citations = initializer.citations;
        if (initializer.feedback !== undefined) this.feedback = initializer.feedback;
    }

}

export interface CompanyType {
    id: number;
    name: string;
    state: string;
    zipcode: string;
    address: string;
}

export class Company {
    id: number | undefined;
    name: string = '';
    state: string = '';
    zipcode: number | undefined;
    address: string = '';

    constructor(initializer?: any){
        if (!initializer) return;
        if (initializer.id) this.id = initializer.id;
        if (initializer.name) this.name = initializer.name;
        if (initializer.state) this.state = initializer.state;
        if (initializer.zipcode) this.zipcode = initializer.zipcode;
        if (initializer.address) this.address = initializer.address;
    }


}

export interface ConversationType {
    id: number;
    title: string;
    conversationDetail: ConversationPrompt[];
    tokens_in?: number | null;
    tokens_out?: number | null;
}

export class Conversation {
    id: number | undefined;
    title: string ='';
    conversationDetail: ConversationPrompt[] = [];
    account: Account | undefined;
    tokens_in: number | null = null;
    tokens_out: number | null = null;

    constructor(initializer?: any){
        if(!initializer) return;
        if (initializer.id) this.id = initializer.id;
        if (initializer.title) this.title = initializer.title;
        if (initializer.conversationDetail) this.conversationDetail = initializer.conversationDetail;
        if (initializer.account) this.account = initializer.account;
        if (initializer.tokens_in !== undefined) this.tokens_in = initializer.tokens_in;
        if (initializer.tokens_out !== undefined) this.tokens_out = initializer.tokens_out;
    }
}

export interface AnnouncementType {
    status: string;
    message: string;
}

export class Announcement {
    status: string = 'default';
    message: string ='';

    constructor(initializer?: any){
        if (!initializer) return;
        if (initializer.status) this.status = initializer.status;
        if (initializer.message) this.message = initializer.message;
    }
}

export interface DocumentType {
    id: number;
    name: string;
    date_uploaded: string;
    created: string;
    file: string;
    active: boolean;
    processed: boolean;
}

export interface FeedbackType {
    id: number;
    title: string;
    status: string;
    text: string;
    category: string;
}

export class Document {
    id: number = 0;
    name: string = '';
    file: string = '';
    date_uploaded: string = '';
    active: boolean = false;
    processed: boolean = false;
    constructor(initializer?: any){
        if(!initializer) return;
        if (initializer.id) this.id = initializer.id;
        if (initializer.name) this.name = initializer.name;
        if (initializer.file) this.file = initializer.file;
        if (initializer.active) this.active = initializer.active;
        if (initializer.date_uploaded) this.date_uploaded = initializer.date_uploaded;
        if (initializer.processed) this.processed = initializer.processed;

    }
}

export class Feedback {
    id: number = 0;
    title: string = '';
    status: string = '';
    text: string = '';
    category: string = '';
    constructor(initializer?: any){
        if(!initializer) return;
        if (initializer.id) this.id = initializer.id;
        if (initializer.status) this.status = initializer.status;
        if (initializer.title) this.title = initializer.title;
        if (initializer.text) this.text = initializer.text;
        if (initializer.category) this.category = initializer.category;

    }
}

export interface UserPromptAnalyticsType {
    month: string,
    you: number,
    others: number,
    all: number,
}

export class UserPromptAnalytics {
    month: string = "";
    you: number = 0;
    others: number = 0;
    all: number = 0;
    constructor(initializer?: any){
        if(!initializer) return;
        if (initializer.id) this.month = initializer.month;
        if (initializer.id) this.you = initializer.you;
        if (initializer.id) this.others = initializer.others;
        if (initializer.id) this.all = initializer.all;
    }

}

export interface UserConvesationAnalyticsType {
    month: string,
    you: number,
    others: number,
    all: number,
}

export class UserConversationAnalytics {
    month: string = "";
    you: number = 0;
    others: number = 0;
    all: number = 0;
    constructor(initializer?: any){
        if(!initializer) return;
        if (initializer.id) this.month = initializer.month;
        if (initializer.id) this.you = initializer.you;
        if (initializer.id) this.others = initializer.others;
        if (initializer.id) this.all = initializer.all;
    }

}

export interface CompanyUsageAnalyticsType {
    month: string,
    used: number,
    not_used: number,
}

export class CompanyUsageAnalytics {
    month: string = "";
    used: number = 0;
    not_used: number = 0;
    constructor(initializer?: any){
        if(!initializer) return;
        if (initializer.id) this.month = initializer.month;
        if (initializer.id) this.used = initializer.used;
        if (initializer.id) this.not_used = initializer.not_used;
    }

}

export interface AdminAnalyticsType {
    month: string,
    range: [number, number],
    avg: number,
    median: number,
}

export class AdminAnalytics {
    month: string = "";
    range: [number, number] = [0, 0];
    avg: number = 0;
    median: number = 0;
    constructor(initializer?: any){
        if(!initializer) return;
        if (initializer.id) this.month = initializer.month;
        if (initializer.id) this.range = initializer.range;
        if (initializer.id) this.avg = initializer.avg;
        if (initializer.id) this.median = initializer.median;
    }

}

export interface AccountType {
    id?: number;
    email: string;
    first_name: string;
    last_name: string;
    role: string  | undefined;
    company: Company | undefined;
    has_usable_password: boolean;
    is_company_manager: boolean;
    is_active: boolean;
    has_signed_tos: boolean;
}

export interface PreferencesType {
    order: boolean;
    use_conversation_context?: boolean;
}

export class Account {
    id?: number;
    email: string = '';
    first_name: string ='';
    last_name: string = '';
    role: string  | undefined;
    company: Company | undefined;
    is_company_manager: boolean = false;
    has_password: boolean = false;
    is_active: boolean = false;
    has_signed_tos: boolean = false;
    constructor(initializer?: any){
        if (!initializer) return;
        if (initializer.id != null) this.id = Number(initializer.id);
        if (initializer.email) this.email = initializer.email;
        if (initializer.first_name) this.first_name = initializer.first_name;
        if (initializer.is_company_manager) this.is_company_manager = initializer.is_company_manager;
        if (initializer.has_password) this.has_password = initializer.has_password;
        if (initializer.is_active) this.is_active = initializer.is_active;
        if (initializer.has_signed_tos) this.has_signed_tos = initializer.has_signed_tos;
        if (initializer.last_name) this.last_name = initializer.last_name;
        if (initializer.role) this.role = initializer.role;
        if (initializer.company) this.company = initializer.company;
        
    }
}
