import 'package:intl/intl.dart'; class ScheduleModel { String category; bool enable; ScheduleFunctionData function; String time; String scheduleId; String timezoneId; List days; ScheduleModel({ required this.category, required this.enable, required this.function, required this.time, required this.scheduleId, required this.timezoneId, required this.days, }); // Factory method to create an instance from JSON factory ScheduleModel.fromJson(Map json) { return ScheduleModel( category: json['category'], enable: json['enable'], function: ScheduleFunctionData.fromJson(json['function']), time:getTimeIn12HourFormat( json['time']), scheduleId: json['scheduleId'], timezoneId: json['timezoneId'], days: List.from(json['days']), ); } // Method to convert an instance into JSON Map toJson() { return { 'category': category, 'enable': enable, 'function': function.toJson(), 'time': time, 'scheduleId': scheduleId, 'timezoneId': timezoneId, 'days': days, }; } } class ScheduleFunctionData { String code; bool value; ScheduleFunctionData({ required this.code, required this.value, }); // Factory method to create an instance from JSON factory ScheduleFunctionData.fromJson(Map json) { return ScheduleFunctionData( code: json['code'], value: json['value'], ); } // Method to convert an instance into JSON Map toJson() { return { 'code': code, 'value': value, }; } } String getTimeIn12HourFormat(time) { // Parse the time string (in HH:mm format) final DateFormat inputFormat = DateFormat("HH:mm"); final DateFormat outputFormat = DateFormat("h:mm a"); // 12-hour format with AM/PM // Convert the time string DateTime parsedTime = inputFormat.parse(time); return outputFormat.format(parsedTime); }