/**
 * CreateBlogHandler
 * CreateBlogCommand handler
 */
export class CreateBlogHandler {
  constructor(blogRepository) {
    this.blogRepository = blogRepository;
  }

  async handle(command) {
    const validation = command.validate();
    if (!validation.isValid) {
      throw new Error(`Validation failed: ${validation.errors.join(', ')}`);
    }

    const blogData = {
      title: command.title,
      content: command.content,
      authorId: command.authorId,
      published: command.published
    };

    const blog = await this.blogRepository.create(blogData);
    return blog;
  }
}
