mirrored_repositories/app_filmes/lib/modules
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'package:app_filmes/application/ui/loader/loader_mixin.dart';
import 'package:app_filmes/application/ui/messages/messages_mixin.dart';
import 'package:app_filmes/models/movie_detail_model.dart';
import 'package:app_filmes/services/movies/movies_service.dart';

class MovieDetailController extends GetxController
    with LoaderMixin, MessagesMixin {
  MovieDetailController({
    required MoviesService moviesService,
  }) : _moviesService = moviesService;

  final MoviesService _moviesService;
  var loading = false.obs;
  var message = Rxn<MessageModel>();
  var movie = Rxn<MovieDetailModel>();

  @override
  void onInit() {
    super.onInit();
    loaderListener(loading);
    messageListener(message);
  }

  @override
  void onReady() async {
    super.onReady();
    try {
      final movieId = Get.arguments;
      loading(true);
      final movieDetailData = await _moviesService.getDetail(movieId);
      movie.value = movieDetailData;
      loading(false);
    } catch (e, s) {
      debugPrint(e.toString());
      debugPrint(s.toString());
      loading(false);
      MessageModel.error(
        title: 'Erro',
        message: 'Erro ao buscar detalhe do filme',
      );
    }
  }
}
