import { connect } from "mongoose";
import Posts from "../../Models/Posts/Posts";
import {
    DeletePostParams,
    GetPostParams,
    IPost,
    PaginatePostsParams,
    PaginatePostsResults,
    SavePostParams,
} from "../../Models/Posts/Posts.Interface";

export class PostsService {
    public async savePost(data: SavePostParams): Promise<IPost> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return Posts.savePost(data);
    }

    public async deletePost(data: DeletePostParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return Posts.deletePost(data);
    }

    public async paginate(data: PaginatePostsParams): Promise<PaginatePostsResults> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return Posts.paginate(data);
    }

    public async getPost(data: GetPostParams): Promise<IPost> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return await Posts.getPost(data);
    }
}
