import { Document } from "mongoose";

export interface IPost {
    id?: string;
    _id?: string;
    companyId: string;
    content: string;
    fixed: boolean;
    fixedOrder: number;
    createdAt: Date;
}

export interface IPostDocument extends Omit<IPost, "id" | "_id">, Document {
    _id: string;
}

export interface IPostAdapter {
    create(data: Omit<CreatePostParams, "sessionUser">): Promise<IPost>;
    update(data: Omit<UpdatePostParams, "sessionUser">): Promise<IPost>;
    delete(data: Omit<DeletePostParams, "sessionUser">): Promise<void>;
    find(filters: Omit<FindPostsParams, "sessionUser">): Promise<IPost[]>;
    findOne(filters: Omit<FindPostsParams, "sessionUser">): Promise<IPostDocument | null>;
    paginate(filters: PaginatePostsParams): Promise<PaginatePostsResults>;
}

export type FindPostsParams = {
    id?: string;
    companyId?: string;
    fixed?: boolean;
    sessionUser?: string;
};

export type GetPostParams = {
    id: string;
};

export type PaginatePostsParams = FindPostsParams & {
    page: number;
    limit: number;
};

export type PaginatePostsResults = {
    data: IPost[];
    page: number;
    pages: number;
    authorizedUsers: string[];
};

export type CreatePostParams = {
    companyId: string;
    content: string;
    sessionUser: string;
};

export type UpdatePostParams = {
    postId: string;
    companyId: string;
    content: string;
    fixed?: boolean;
    fixedOrder?: number;
    sessionUser: string;
};

export type SavePostParams = {
    postId?: string;
    companyId: string;
    content: string;
    fixed?: boolean;
    fixedOrder?: number;
    sessionUser: string;
};

export type DeletePostParams = {
    id: string;
    companyId: string;
    sessionUser: string;
};

export type DeletePostsByCompanyParams = {
    companyId: string;
};

export interface IPostsManager {
    posts: IPostAdapter;
    deletePostsByCompany(data: DeletePostsByCompanyParams): Promise<void>;
    createPost(data: CreatePostParams): Promise<IPost>;
    updatePost(data: UpdatePostParams): Promise<IPost>;
    savePost(data: SavePostParams): Promise<IPost>;
    deletePost(data: DeletePostParams): Promise<void>;
    paginate(data: PaginatePostsParams): Promise<PaginatePostsResults>;
    getPost(data: GetPostParams): Promise<IPost>;
}
