import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:json_annotation/json_annotation.dart';
import '../screen/pageDetail/campaign_detail_screen.dart';
import '../shared/router_gage.dart';
import 'directional_action_type.dart';

part 'directional_screen.g.dart';

@JsonSerializable()
class DirectionalScreen {
  @JsonKey(name: "click_action_type")
  final String? clickActionType;
  @JsonKey(name: "click_action_param")
  final String? clickActionParam;

  DirectionalScreen({this.clickActionType, this.clickActionParam});

  static DirectionalScreen? build({String? clickActionType, String? clickActionParam}) {
    if (clickActionType == null || clickActionType.isEmpty) return null;
    return DirectionalScreen(clickActionType: clickActionType, clickActionParam: clickActionParam);
  }

  factory DirectionalScreen.fromJson(Map<String, dynamic> json) => _$DirectionalScreenFromJson(json);
  Map<String, dynamic> toJson() => _$DirectionalScreenToJson(this);

  @immutable
  bool begin() {
    final type = DirectionalScreenNameExtension.fromRawValue(clickActionType ?? "");
    if (type == null) {
      print("Không nhận diện được action type: $clickActionType");
      return false;
    }
    switch (type) {
      case DirectionalScreenName.setting:
        Get.toNamed(settingScreen);
        return true;
      case DirectionalScreenName.productOwnVoucher:
        Get.toNamed(voucherDetailScreen, arguments: {"customerProductId": int.parse(clickActionParam ?? "")});
        return true;
      default:
        print("Không nhận diện được action type: $clickActionType");
        return false;
    }
  }
}
