import 'package:json_annotation/json_annotation.dart';

import '../../../api_response.dart';

part 'timetable_get_schoolyear_response.g.dart';

@JsonSerializable(explicitToJson: true)
class TimetableGetSchoolyearResponse extends ApiResponse {
  final int id;
  final String name;

  @JsonKey(fromJson: _dateFromJson, toJson: _dateToJson)
  final DateTime startDate;

  @JsonKey(fromJson: _dateFromJson, toJson: _dateToJson)
  final DateTime endDate;

  TimetableGetSchoolyearResponse({
    required this.id,
    required this.name,
    required this.startDate,
    required this.endDate,
  });

  factory TimetableGetSchoolyearResponse.fromJson(Map<String, dynamic> json) =>
      _$TimetableGetSchoolyearResponseFromJson(json);
  Map<String, dynamic> toJson() =>
      _$TimetableGetSchoolyearResponseToJson(this);

  static DateTime _dateFromJson(String raw) => DateTime.parse(raw);
  static String _dateToJson(DateTime d) =>
      '${d.year.toString().padLeft(4, '0')}-${d.month.toString().padLeft(2, '0')}-${d.day.toString().padLeft(2, '0')}';
}
