summaryrefslogtreecommitdiff
path: root/lib/Travel/Routing/DE/DBRIS/Offer.pm
blob: a87216bdb4ebdda163c33f3033d777a31dc123c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package Travel::Routing::DE::DBRIS::Offer;

use strict;
use warnings;
use 5.020;
use utf8;

use parent 'Class::Accessor';

our $VERSION = '0.03';

Travel::Routing::DE::DBRIS::Offer->mk_ro_accessors(
	qw(class name price price_unit is_upsell is_cross_sell needs_context));

sub new {
	my ( $obj, %opt ) = @_;

	my $json = $opt{json};

	my $ref = {
		class         => $json->{klasse} =~ s{KLASSE_}{}r,
		name          => $json->{name},
		price         => $json->{preis}{betrag},
		price_unit    => $json->{preis}{waehrung},
		conditions    => $json->{konditionsAnzeigen},
		is_upsell     => exists $json->{upsellInfos}    ? 1 : 0,
		is_cross_sell => exists $json->{crosssellInfos} ? 1 : 0,
	};

	for my $relation ( @{ $json->{angebotsbeziehungList} // [] } ) {
		for my $offer_ref ( @{ $relation->{referenzen} // [] } ) {
			if ( $offer_ref->{referenzAngebotsoption} eq 'PFLICHT' ) {
				$ref->{needs_context} = 1;
			}
		}
	}

	bless( $ref, $obj );

	return $ref;
}

sub conditions {
	my ($self) = @_;

	return @{ $self->{conditions} // [] };
}

1;